﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace SDWXServer.Models
{
    public class WXValidateCode
    {
        public WXValidateCode()
        {
            SetNewCode();
        }
        public string Id { get; set; }
        public string Code { get; set; }
        public DateTime ExpiryDate { get; set; }
        public DateTime SendTime { get; set; }
        public void SetNewCode()
        {
            this.Code = RandomNumSupplier.GetVCode();
            this.ExpiryDate = DateTime.Now.AddMinutes(5d);
            this.SendTime = DateTime.Now.AddMinutes(-2d);
        }
    }
    public class RandomNumSupplier
    {
        private const string BASECODE = "0123456789";
        static Random ranNum = new Random(unchecked((int)DateTime.Now.Ticks));

        public static string GetVCode()
        {
            var length = 6;
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < length; i++)
            {
                int rnNum = ranNum.Next(BASECODE.Length);
                builder.Append(BASECODE[rnNum]);
            }
            return builder.ToString();
        }
    }
}